<?php
class services extends baseController {    
	public function __construct() {
		parent::__construct ();
	}
    
    public function loadView($temp) {
        if (!isset($temp["data"]))
            $temp["data"] = '';
        $this->load->view("template", $temp);
    }
    
    public function index($slug) {
        $this->session->set_userdata('selectedMenu', 'services');
        $services = $this->servicesModel->read(array('slug' => $slug, 'languageCode' => $this->session->userdata('languageCode')));
        if(!$services) {
            $first = $this->servicesModel->getMin('servicesId');
            $services = $this->servicesModel->read(array('servicesId' => $first['servicesId'], 'languageCode' => $this->session->userdata('languageCode')));
            if(!$services) {
                redirect(base_url());
                return;
            }
        }
        $this->session->set_userdata('servicesDisplay', $services['servicesId']);
        $this->_data["template"] = 'services';
        $this->_data["data"] = $services;
        $this->_data["subs"] = $this->servicesModel->get_by(array('parentId' => $services['servicesId'], 'languageCode' => $this->session->userdata('languageCode')));;
        $this->loadView($this->_data);
    }
    
    public function updateLanguage() {
        $services = $this->servicesModel->get_by(array('languageCode' => 'du', 'parentId >' => 0));
        foreach($services as $key => $value) {
            $servicesId = $value['servicesId'];
            $data = $this->servicesModel->read(array('languageCode' => 'en', 'servicesId' => $servicesId));
            $data['id'] = $value['id'];
            $data['languageCode'] = 'du';
            $this->servicesModel->update($data);
        }
    }
}
?>